package com.wsoft.portal.controller;

import com.wsoft.portal.query.theme.ThemeInsertQuery;
import com.wsoft.portal.query.theme.ThemeListQuery;
import com.wsoft.portal.query.theme.ThemeUpdateEnableQuery;
import com.wsoft.portal.query.theme.ThemeUpdateQuery;
import com.wsoft.portal.service.IPortalThemeService;
import com.wsoft.response.ResponsePage;
import com.wsoft.response.ResponseResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * 主题 前端控制器
 * @author Z001
 * @since 2024年12月27日 10:00:40
 */
@RestController
@Tag(name = "主题")
@RequestMapping("/portal/theme")
public class PortalThemeController {

    @Resource
    private IPortalThemeService themeService;

    @Operation(summary = "新增主题", description = "新增主题")
    @PostMapping("/insert")
    public ResponseResult insert(@RequestBody @Valid ThemeInsertQuery query) {
        boolean b = themeService.insertTheme(query);
        if (b) {
            return ResponseResult.success("[sys.msg.success]");
        } else {
            return ResponseResult.failed("[sys.msg.failed]");
        }
    }

    @Operation(summary = "修改主题", description = "修改主题")
    @PostMapping("/update")
    public ResponseResult update(@RequestBody @Valid ThemeUpdateQuery query) {
        boolean b = themeService.updateTheme(query);
        if (b) {
            return ResponseResult.success("[sys.msg.success]");
        } else {
            return ResponseResult.failed("[sys.msg.failed]");
        }
    }

    @Operation(summary = "启用/不启用", description = "启用/不启用")
    @PostMapping("/enable")
    public ResponseResult enable(@RequestBody @Valid ThemeUpdateEnableQuery query) {
        boolean b = themeService.updateThemeEnable(query);
        if (b) {
            return ResponseResult.success("[sys.msg.success]");
        } else {
            return ResponseResult.failed("[sys.msg.failed]");
        }
    }

    @Operation(summary = "主题详情页面", description = "主题详情页面")
    @GetMapping("/get")
    public ResponseResult get(@RequestParam("id") Long id) {
        return ResponseResult.success(themeService.getThemeId(id));
    }


    @Operation(summary = "删除待办配置", description = "删除待办配置")
    @GetMapping("/delete")
    public ResponseResult dropTheme(@RequestParam("id") Long id) {
        boolean b = themeService.deleteTheme(id);
        if (b) {
            return ResponseResult.success("[sys.msg.success]");
        } else {
            return ResponseResult.failed("[sys.msg.failed]");
        }
    }

    @Operation(summary = "查询列表", description = "查询列表")
    @PostMapping("/list")
    public ResponseResult list(@RequestBody ThemeListQuery query) {
        return ResponseResult.success(ResponsePage.restPage(themeService.listTheme(query)));
    }

}
